Skip to content

New windows impl#121

Merged
Xaeroxe merged 7 commits intoharryfei:masterfrom
Xaeroxe:new-windows-impl
Mar 8, 2026
Merged

New windows impl#121
Xaeroxe merged 7 commits intoharryfei:masterfrom
Xaeroxe:new-windows-impl

Conversation

@Xaeroxe
Copy link
Copy Markdown
Collaborator

@Xaeroxe Xaeroxe commented Mar 7, 2026

Moves the crate into a virtual workspace, then adds a small code generation binary for generating Windows FFI bindings. These bindings are then committed to the repo and used in the which crate. The code generation binary is not intended for distribution.

This is considered preferable because winsafe's current version is using an MSRV of 1.87, which is faster than I want to move which's MSRV at this time. Older versions of winsafe are suffering from rodrigocfd/winsafe#185

Additionally we only need two functions from Windows, so bringing in most of the API bindings feels excessive.

@Xaeroxe Xaeroxe force-pushed the new-windows-impl branch from 9aecbb4 to a6e43dd Compare March 7, 2026 19:54
@Xaeroxe Xaeroxe force-pushed the new-windows-impl branch from a6e43dd to e12e7b6 Compare March 7, 2026 20:00
@Xaeroxe Xaeroxe force-pushed the new-windows-impl branch from f16f0c4 to 54730c6 Compare March 7, 2026 20:02
@Xaeroxe
Copy link
Copy Markdown
Collaborator Author

Xaeroxe commented Mar 7, 2026

@madsmtm Hey do you mind giving me a quick code review here? The unsafe usage is pretty straightforward but I'd feel better if someone double checked me.

@rodrigocfd
Copy link
Copy Markdown

winsafe's current version is using an MSRV of 1.87

Hi @Xaeroxe, winsafe author here. What MSRV are you aiming at?

Copy link
Copy Markdown
Contributor

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the unsafe part looks fine.

Whether which should use winsafe or not is a complex discussion. I tend to lean towards "no", for a few reasons:

  • The which crate is quite widely used, so any dependencies it has is dependencies that users are gonna have.
  • The winsafe crate isn't that widely used, so the dependency isn't going to be shared with other dependencies, and there's security implications with the increased supply chain.
  • The windows-rs crates (windows-link in this case) are widely used, and directly from Microsoft, so the above issues aren't really a problem there.

There are benefits to winsafe, especially if which was using a bunch of Windows functions, but it isn't, it's using two simple functions, hence why I think it makes sense to not depend on it.

The same arguments apply for the rustix crate, it's used in one place so using libc directly might be the better option, though less so because it's also more popular.

(@rodrigocfd I hope you understand that I mean no slight against you or your crate, I'm only commenting on factors largely outside your control. I also get that it's a chicken and egg problem, from winsafe's perspective, you really want which as a depender, since it'll grow your download count and probably userbase, which should make the "winsafe isn't widely used" be less of a problem for others).

Comment thread gen-windows-bindings/Cargo.toml Outdated
Comment thread which/Cargo.toml Outdated
Comment thread which/Cargo.lock Outdated
Comment thread which/src/win_ffi.rs Outdated
@rodrigocfd
Copy link
Copy Markdown

@madsmtm Yes, I would love to have which as a depender of winsafe, but I do understand. Thank you for taking time to explain your reasons.

Anyway, since all you guys need is 2 rather simple calls, it seems that you're still adding unnecessary complexity with windows-bindgen and all this workspace setup.

You can reference the 2 functions directly:

#[link(name = "kernel32")]
unsafe extern "system" {
  pub fn GetBinaryTypeW(app_name: *const u16, bin_type: *mut u32) -> i32;
  pub fn GetLastError() -> u32;
}

That means zero dependencies for Windows.

Let me know if you need any help with this.

@Xaeroxe
Copy link
Copy Markdown
Collaborator Author

Xaeroxe commented Mar 8, 2026

There's also another perspective to consider which is probably only apparent to me as a long term maintainer.

which doesn't get updated all that often, and that's for the better. Our users aren't expecting or wanting new features, they want a reliable way to perform a task which computers have been doing for decades. This isn't a place to try out new ideas, or be creative. Our users usually invoke a single simple function, and they are happiest when they don't have to think about which.

From a feature standpoint, which has been perfected. It is entirely plausible that no new major API changes happen ever again, and I would not view this as a tragedy. The reason that which requires maintenance work most often is to update or accommodate a new dependency. So my vision of the future for which is a future of utmost stability and very slow movement. I get closer to that future every time a dependency is removed.

Thank you for being understanding of this @rodrigocfd and I support your mission to make the usage of Windows APIs safer for us all!

@Xaeroxe Xaeroxe force-pushed the new-windows-impl branch 5 times, most recently from 05b42a2 to 78540b6 Compare March 8, 2026 17:55
@Xaeroxe Xaeroxe force-pushed the new-windows-impl branch from 78540b6 to 61c1656 Compare March 8, 2026 17:57
@Xaeroxe Xaeroxe merged commit 189e99a into harryfei:master Mar 8, 2026
17 checks passed
@Xaeroxe Xaeroxe deleted the new-windows-impl branch March 8, 2026 18:05
@Xaeroxe Xaeroxe mentioned this pull request Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants